/**
 * Created with IntelliJ IDEA.
 * Description:查找总价格为目标值的两个商品
 * User: bjc
 * Date: 2025-11-05
 * Time: 10:58
 */
public class Test06_twoSum {
    public static int[] twoSum(int[] price, int target) {
        int left = 0,right = price.length-1;
        int[] ret = new int[2];
        while(left < right){
            if(price[left] + price[right] > target){
                right--;
            }else if(price[left] + price[right] < target){
                left++;
            }else{
                ret[0] = price[left];
                ret[1] = price[right];
                return ret;
            }
        }
        return ret;
    }
    public static void main(String[] args) {
        int[] price = {3, 9, 12, 15};
        int target = 18;
        int[] ret = twoSum(price,target);
        System.out.println(ret[0]+" "+ret[1]);
    }
}
